<?php
ALFileLoad::lib(ALViewController);

ALFileLoad::appfile("users/models.php");
ALFileLoad::appfile("users/forms.php");

class hi extends ALViewController {

    public function doGet ($request) {
        
        $request->view->type = $request->params['type'];
        return $request->view->render('hi.php');

    }

}

class index extends ALViewController
{
	public function doGet($request)
	{
		dump($_SERVER);
		return $request->view->render('testing.php');
	}
	
	public function doPost($request)
	{
		dump($request->params['goodtimes']);
	}
}

class sqlTransaction extends ALViewController
{

	public function doGet($request)
	{

		$db = new ALDataObject('mytest','users');
		$db->beginTransaction();
		$db->exec('
			INSERT INTO
				users
			SET
				username = \'brandon\',
				password = \'theman\'
			');
		// $db->rollBack();
		$db->commit();

		return $request->view->render('sqlTransaction.php');

	}

}

class formbuild extends ALViewController
{
	public function doGet($request)
	{
		ALFileLoad::lib(ALFormatParser);

		$form = new LoginForm;
		$request->view->form = $form->load();
		return $request->view->render('forming.php');
	}
	
	public function doPost($request)
	{
		$form = new LoginForm($request->params);
		
		if(!$form->isValid())
			$request->view->form = $form->load();
		else
			redirect('/users/formbuild');
			 
		return $request->view->render('forming.php');
		
	}
}

class socketCurl extends ALViewController
{
	public function doGet($request)
	{
		ALFileLoad::lib(ALURLConnection);
		
		$data = array(
				'test' 	=> 'this is a test',
				'foo'	=> 'bar'
			);
		//$url = "http://localhost/info.php"; //get test
		$url = "http://actionleaf.local/users/socket";
		$urlConnection = new ALURLConnection;
		$urlRequest = $urlConnection->post($url, $data);
		dump($urlRequest);
	}
	
	public function doPost($request)
	{
		dump($request);
	}
}
